<template>
  <div id="cornerComment" v-if="dialogVisible">
    <div class="cornerComment-in">
      <div class="cornerComment-in-title">
        <span>编辑区角类目</span>
        <span class="el-icon-circle-close close-Btn-line" @click="closePOpup"></span>
      </div>
      <div class="commentBody">
        <el-form label-width="100px" ref="editForm">
          <el-form-item label="缩略图：" prop="num">
            <imgUploadModle @getChildValue="getChildValue" imgNumber="1" page="teachingPic"
                            :picSrc="editForm.pic"></imgUploadModle>
          </el-form-item>
          <el-form-item label="类目名称：" prop="num">
            <el-input v-model="editForm.name" placeholder="类目名称" size="small"></el-input>
          </el-form-item>
          <el-form-item label="达标时长：" prop="num">
            <el-input v-model="editForm.time" placeholder="达标时长" size="small">
              <template slot="append">分钟</template>
            </el-input>
          </el-form-item>
          <el-form-item label="基本分值：" prop="num">
            <el-input v-model="editForm.base_score" placeholder="基本分值" size="small"></el-input>
          </el-form-item>
          <el-form-item label="每节课时长：" prop="num">
            <el-input v-model="editForm.one_time" placeholder="每节课时长" size="small">
              <template slot="append">分钟</template>
            </el-input>
          </el-form-item>
        </el-form>
      </div>
      <div class="cornerComment-in-footer">
        <el-button @click.native="closePOpup" size="small">取消</el-button>
        <el-button size="small" type="primary" @click="checkEditFn">确定并保存</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import {cornerCateEdit, cornerCateAdd, cornerCateDetail} from '@/api/admin/corner'

export default {
  props: ['visible', 'warehouseId'], // recruitmentType examine 审核
  components: {},
  data() {
    return {
      dialogVisible: false,
      name: '',
      editForm: {
        name: '',// 	整型 	必填 	1 	- 	名称
        time: '',// 	整型 	必填 	1 	- 	达标时长
        one_time: 45,//	整型 	必填 	1 	- 	每次使用分钟
        base_score: '',// 	整型 	必填 	1 	- 	基础分
        description: '',// 	整型 	必填 	1 	- 	简介
        pic: ''
      }
    }
  },
  watch: {
    visible() {
      this.dialogVisible = this.visible
      if (this.visible) {
        if (this.warehouseId) {
          this.getDetail()
        }
      } else {
        this.editForm = {
          name: '',// 	整型 	必填 	1 	- 	名称
          time: '',// 	整型 	必填 	1 	- 	达标时长
          one_time: 45,//	整型 	必填 	1 	- 	每次使用分钟
          base_score: '',// 	整型 	必填 	1 	- 	基础分
          description: '',// 	整型 	必填 	1 	- 	简介
          pic: ''
        }
      }
    }
  },
  created() {

  },
  methods: {
    async checkEditFn() {
      if (!this.editForm.name) {
        this.$message.error('填写类目名称')
        return
      }
      if (!this.editForm.time) {
        this.$message.error('填写达标时长')
        return
      }
      if (!this.editForm.one_time) {
        this.$message.error('填写每节课时长')
        return
      }
      if (!this.editForm.base_score) {
        this.$message.error('填写基本分值')
        return
      }
      let data_ = this.getJson(this.editForm);
      if (this.warehouseId) {
        data_.id = this.warehouseId
        cornerCateEdit(data_).then(res => {
          if (!res.code) {
            this.$message.success(res.msg)
            this.$emit('InitFn')
          } else {
            this.$message.error(res.msg)
          }
        })
      } else {
        cornerCateAdd(data_).then(res => {
          if (!res.code) {
            this.$message.success(res.msg)
            this.$emit('InitFn')
            this.closePOpup()
          } else {
            this.$message.error(res.msg)
          }
        })
      }
    },
    async getDetail() {
      cornerCateDetail({id: this.warehouseId}).then(res => {
        console.log('res:', res)
        for (let index in this.editForm) {
          console.log('index:', index)
          this.editForm[index] = res.vo[index]
        }
      })
    },
    // 关闭弹窗
    closePOpup() {
      this.$emit('update:visible', false)
    },
    getJson(option) {
      return JSON.parse(JSON.stringify(option))
    },
    getChildValue(option) {
      this.editForm.pic = option
    },
  },
  mounted() {
  }
}
</script>
<style scoped>
#cornerComment {
  height: 100vh;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9;
}

.cornerComment-in {
  width: 500px;
  height: 560px;
  background: #fff;
  display: flex;
  flex-direction: column;
  border-radius: 5px;
}

.cornerComment-in-title {
  height: 50px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ddd;
  font-size: 24px;
}

.cornerComment-in-title span {
  padding: 0 10px;
}

.cornerComment-in-title span:first-child {
  flex: 1;
  font-size: 16px;
}

.cornerComment-in-footer {
  height: 50px;
  border-top: 1px solid #ddd;
  display: flex;
  align-items: center;
  padding: 0 10px;
  justify-content: center;
}

.commentBody {
  padding: 20px 20px 0;
  flex: 1;
  overflow-y: auto;
}

.close-Btn-line {
  cursor: pointer;
}

.resruitment-title {
  padding: 5px 0;
  border-bottom: 2px solid #abd3f3;
  margin-bottom: 20px;
}

.el-radio {
  margin-right: 20px;
}

.jobTime {
  display: flex;
  align-items: center;
}

.jobTime span {
  padding: 0 10px;
}
</style>


